Ext.define('NF.view.farm.LivestockSearchPanel', {
    extend:'Ext.grid.Panel',
    alias:'widget.livestocksearchpanel',
    itemId:Ext.id('livestocksearchpanel'),
    frame:true,
    store:'LivestockSearch',
    autoScroll:true,
    dockedItems:[
        {
            xtype: 'pagingtoolbar',
            store:'LivestockSearch',   // same store GridPanel is using
            dock: 'top',
            displayInfo: true
        }
    ],
    initComponent:function() {
        var self = this;
        this.columns = [
            Ext.create('Ext.grid.RowNumberer'),
            {header:'Livestock ID',dataIndex:'id',flex:1},
            {header:'Livestock name',dataIndex:'name',flex:1}
        ];
        this.callParent(arguments);
        this.loadLivestockList(self.model.context);
        if (self.model.context.searchBy === 'Id') {
            this.setTitle(self.model.context.searchBy + ' #' + self.model.context.value + " Livestock");
        } else {
            this.setTitle(self.model.context.searchBy + ' - ' + self.model.context.value + " Livestock");
        }
    },
    loadLivestockList:function(paramData) {
        var self = this;
        var livestockStore = this.getStore();
        if (paramData.searchBy === 'Id') {
            livestockStore.getProxy().extraParams.searchBy = 'id'; //paramData.;
        } else {
            livestockStore.getProxy().extraParams.searchBy = 'name'; //paramData.;
        }
        livestockStore.getProxy().extraParams.value = paramData.value;
        livestockStore.load();
    }
});
